package com.inspector.app.ui.chat;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;

import com.blankj.utilcode.util.ToastUtils;
import com.hbzhou.open.flowcamera.listener.FlowCameraListener;
import com.inspector.app.R;
import com.inspector.app.databinding.ActivityVideoRecorderBinding;
import com.inspector.app.ui.base.BaseDJActivity;

import java.io.File;

/**
 * 视频拍摄
 */
public class VideoRecorderActivity extends BaseDJActivity {
    private ActivityVideoRecorderBinding viewDataBinding;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        viewDataBinding = DataBindingUtil.setContentView(this, R.layout.activity_video_recorder);
        viewDataBinding.setLifecycleOwner(this);
        // 绑定生命周期 您就不用关心Camera的开启和关闭了 不绑定无法预览
        viewDataBinding.customCamera.setBindToLifecycle(this);
        // 设置最大可拍摄小视频时长
        viewDataBinding.customCamera.setRecordVideoMaxTime(60);
        // 设置拍照或拍视频回调监听
        viewDataBinding.customCamera.setFlowCameraListener(new FlowCameraListener() {
            @Override
            public void captureSuccess(@NonNull File file) {
                Intent resultIntent = new Intent();
                resultIntent.putExtra("image", file.getAbsolutePath());
                resultIntent.putExtra("type", 1);
                setResult(Activity.RESULT_OK, resultIntent);
                finish();
            }

            @Override
            public void recordSuccess(@NonNull File file) {
                Intent resultIntent = new Intent();
                resultIntent.putExtra("video", file.getAbsolutePath());
                resultIntent.putExtra("type", 2);
                setResult(Activity.RESULT_OK, resultIntent);
                finish();
            }

            @Override
            public void onError(int videoCaptureError, @NonNull String message, @Nullable Throwable cause) {
                ToastUtils.showLong("异常" + message);
                finish();
            }
        });
        //左边按钮点击事件
        viewDataBinding.customCamera.setLeftClickListener(() -> finish());
    }

    @Override
    protected void onResume() {
        super.onResume();

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();


    }
}
